package com.pb.news4.service.impl;

import java.util.List;

import com.pb.news4.dao.News4CategoryDao;
import com.pb.news4.dao.News4Dao;
import com.pb.news4.dao.impl.News4CategoryDaoImpl;
import com.pb.news4.dao.impl.News4DaoImpl;
import com.pb.news4.entity.News4;
import com.pb.news4.entity.NewsCategory;
import com.pb.news4.service.News4Service;

public class News4ServiceImpl implements News4Service {
	News4Dao news4Dao = new News4DaoImpl();
	News4CategoryDao news4CategoryDao = new News4CategoryDaoImpl();
 	
	public News4Dao getNews4Dao() {
		return news4Dao;
	}

	public void setNews4Dao(News4Dao news4Dao) {
		this.news4Dao = news4Dao;
	}

	public News4CategoryDao getNews4CategoryDao() {
		return news4CategoryDao;
	}

	public void setNews4CategoryDao(News4CategoryDao news4CategoryDao) {
		this.news4CategoryDao = news4CategoryDao;
	}

	@Override
	public List<News4> getNewsList() {
		// TODO Auto-generated method stub
		
		return news4Dao.getNewsList();
	}

	@Override
	public boolean add(News4 news4) {
		// TODO Auto-generated method stub
		return news4Dao.add(news4);
	}

	@Override
	public boolean delete(News4 news4) {
		// TODO Auto-generated method stub
		return news4Dao.delete(news4);
	}

	@Override
	public boolean update(News4 news4) {
		// TODO Auto-generated method stub
		return news4Dao.update(news4);
	}
	
	/**
	 *  删除新闻类别：在删除之前，先查询news_detail表相关类别下有没有新闻信息
	 若有，提示该类别下有新闻信息，请先删除新闻信息
	 若没有，则直接删除
	 */
	@Override
	public boolean deleteNewsCategory(NewsCategory newsCategory) {
		// TODO Auto-generated method stub
		// 根据categoryId查询新闻信息
		boolean flag = false;
		News4 news4 = new News4();
		news4.setCategoryId(newsCategory.getId());
		int count = news4Dao.getNews4Count(news4);
		if(count > 0){
			System.out.println("该类别下有新闻信息，请先删除新闻信息!");
		}else{
			// 根据id删除新闻类别
			flag = news4CategoryDao.deleteNews4Category(newsCategory);
			System.out.println("新闻类别删除成功！");
		}
		return flag;
	}

}
